package com.qfedu.controller;

import com.qfedu.pojo.req.GoodsInfoReq;
import com.qfedu.pojo.resp.BaseResp;
import com.qfedu.service.GoodsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName GoodsInfoController
 * @Description TODO
 * @Author young
 * @Date 2022-09-26 22:40
 * @Version 1.0
 **/
@RestController
@RequestMapping("/goodsInfo")
@Api(tags = "商品管理")
public class GoodsInfoController {

    @Autowired
    GoodsInfoService goodsInfoService;

    @ApiOperation(value = "根据商品名称模糊查询")
    @PostMapping("/findByGoodsName")
    //非json格式数据
    public BaseResp findByGoodsName(@RequestParam String goodsName){
        return goodsInfoService.findByGoodsName("%"+goodsName+"%");
    }

    @ApiOperation(value = "根据二级分类查询")
    @GetMapping("/findByType")
    public BaseResp findByType(Integer secondTypeId){
        return goodsInfoService.findByType(secondTypeId);
    }


    @ApiOperation(value = "根据id查询单个商品")
    @GetMapping("/findById")
    public BaseResp findById(Integer goodsId){
        return goodsInfoService.findById(goodsId);
    }


    @ApiOperation(value = "根据热搜分类id查询热搜商品")
    @GetMapping("/findByHotId")
    public BaseResp findByHotId(Integer hotId){
        return goodsInfoService.findByHotId(hotId);
    }

    @GetMapping("/findAll")
    @ApiOperation(value = "查询全部商品")
    public BaseResp findAll(@RequestParam("page")Integer page,@RequestParam("size")Integer size){
        return goodsInfoService.findAll(page,size);
    }

    @PostMapping("delById")
    @ApiOperation(value = "删除商品")
    public BaseResp delById(@RequestBody GoodsInfoReq goodsInfoReq){
        return goodsInfoService.delById(goodsInfoReq.getGoodsId());
    }
    @PostMapping("saveOrUpdate")
    @ApiOperation(value = "新增或修改商品")
    public BaseResp saveOrUpdate(@RequestBody GoodsInfoReq goodsInfoReq){
        return goodsInfoService.saveOrUpdate(goodsInfoReq);
    }
}

